// 入口文件
const express = require("express"); // 引入express
// 导入接口模块
const user = require('./src/api/user')
const goods = require('./src/api/goods')
const carts = require('./src/api/carts')


// 使用express 创建一个app
const app = express();
//统一设置跨域等问题
app.all('*', function(req, res, next) {  
    res.header("Access-Control-Allow-Origin", "*");  
    res.header("Access-Control-Allow-Headers", "Content-Type");  
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By",'Laosiji')
    res.header("Content-Type", "application/json;charset=utf-8");
    next();  
});  



// 让express 解析请求参数
app.use(express.urlencoded({ extended: false }));
app.use(express.json());

// 绑定接口模块
app.use('/user',user) // 注意前缀
app.use('/goods',goods)
app.use('/carts',carts)

// 监听端口 运行服务
app.listen(3000, () => {
    console.log(`Example app listening at http://localhost:3000`);
});
